﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace DarkNeuron.Services.Input
{
// #if !xbox
	public class ButtonMouse : Button
	{
		protected MouseButtons key;


		public ButtonMouse(string name, MouseButtons key)
			: base(name, ButtonDevice.Mouse)
		{
			Console.WriteLine("ButtonMouse|Information:> New ButtonMouse \"{0}\" is being initialized...", Name);

			bool pass = true;
			this.key = key;

			pass = ButtonManager.AddButton(this);

			if (pass) Console.WriteLine("ButtonMouse|Information:> ButtonMouse \"{0}\" is successfully initialized.", Name);
			else Console.WriteLine("ButtonMouse|Error:> ButtonMouse \"{0}\" is NOT successfully initialized!", Name);
		}


		public override void Update(GameTime gameTime)
		{
			if (Enabled)
			{
				previousButtonState = currentButtonState;
				currentButtonState = CheckState();
			}
			
			
			base.Update(gameTime);
		}
		private ButtonState CheckState()
		{
			// Finds state of correct button on mouse
			switch (key)
			{
				case MouseButtons.Left:
					return GameInput.Mouse.LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed ? ButtonState.Down : ButtonState.Up;
				case MouseButtons.Right:
					return GameInput.Mouse.RightButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed ? ButtonState.Down : ButtonState.Up;
				case MouseButtons.Middle:
					return GameInput.Mouse.MiddleButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed ? ButtonState.Down : ButtonState.Up;
				case MouseButtons.OEMBack:
					return GameInput.Mouse.XButton1 == Microsoft.Xna.Framework.Input.ButtonState.Pressed ? ButtonState.Down : ButtonState.Up;
				case MouseButtons.OEMForward:
					return GameInput.Mouse.XButton2 == Microsoft.Xna.Framework.Input.ButtonState.Pressed ? ButtonState.Down : ButtonState.Up;
				default:
					Console.WriteLine("ButtonMouse|Critical:> key typeof(MouseButtons) provided is not valid! Button Name: {0}", Name);
					return ButtonState.Up;
			}
		}
	}
// #endif
}
